﻿<?php 
include("conn.php");
mysql_query('SET NAMES UTF8'); 
// 需传参数
$cityid = $_REQUEST[cityid];
// 需传参数 end
$ad = array();
$query = mysql_query("select * from ad where cityid='".$cityid."' order by id desc");
$i = 0;
while($rowf=mysql_fetch_array($query)){
	switch ($rowf[type]) {
		case 0:
			$ad[$i][id] = $rowf[id];
			$ad[$i][images] = $rowf[images];
			$ad[$i][type] = $rowf[type];
			$ad[$i][typeName] = '图文广告';
			$ad[$i][content] = $rowf[content];
			break;
		
		case 1:
			// 获取分类名称
			$sql = mysql_query("select name from categroy where cateid=".$rowf[cateid]);
			$cate = mysql_fetch_assoc($sql);
			// 获取分类名称 end
			$ad[$i][id] = $rowf[id];
			$ad[$i][images] = $rowf[images];
			$ad[$i][type] = $rowf[type];
			$ad[$i][typeName] = '分类广告';
			$ad[$i][cateid] = $rowf[cateid];
			$ad[$i][cateName] = $cate[name];
			break;

		case 2:
			$ad[$i][id] = $rowf[id];
			$ad[$i][images] = $rowf[images];
			$ad[$i][type] = $rowf[type];
			$ad[$i][typeName] = '商家广告';
			$ad[$i][shopid] = $rowf[shopid];
			break;
	}
	$i++;
}

$result = array();
$result['code'] = 200;
$result['msg'] = '获取成功';
$result['data'] = $ad;
echo json_encode($result);


?>